﻿using System;
using System.Web;



#region License
/*
 *  Copyright (c) Dumuzi.cn 2009 , All rights reserved.
 *  CLR Version:  2.0.50727.4927
 *  NameSpace: Summer.Web.Support
 *  Author:Edwin Tai,戴佳顺
 *  Msn:edwin19861218@hotmail.com
 *  QQ: 1961218
 *  Date:2009/10/27 16:37:20
 *  Licensed under the Microsoft Public License (Ms-PL)
 *  This license governs use of the accompanying software. 
 *  If you use the software, you accept this license.
 *  If you do not accept the license, do not use the software.
 */
#endregion

namespace Summer.Web.Support
{
    /// <summary>
    /// The base class for Summer Ioc in web application
    /// 
    /// </summary>
    public abstract class AbstractHandlerFactory : IHttpHandlerFactory
    {
        /// <summary>
        /// Get new instance of IHttpHandler
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requestType"></param>
        /// <param name="url"></param>
        /// <param name="pathTranslated"></param>
        /// <returns></returns>
        public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            IHttpHandler handler = this.CreateHandlerWithProperities(context, requestType, url, pathTranslated);
            return handler;
        }
        public abstract void ReleaseHandler(IHttpHandler handler);
        /// <summary>
        /// Create new instance of IHttpHandler by current url data
        /// </summary>
        /// <param name="context"></param>
        /// <param name="requestType"></param>
        /// <param name="url"></param>
        /// <param name="pathTranslated"></param>
        /// <returns></returns>
        protected virtual IHttpHandler CreateHttpHandler(HttpContext context, string requestType, string url, string pathTranslated)
        {
            SummerPageHandlerFactory factory = (SummerPageHandlerFactory)Activator.CreateInstance(typeof(SummerPageHandlerFactory), true);
            IHttpHandler handler = factory.GetHandler(context, requestType, url, pathTranslated);
            return handler;
        }
        /// <summary>
        /// The abstract method in order to overwrite the current page object
        /// </summary>
        /// <param name="handler"></param>
        protected abstract IHttpHandler CreateHandlerWithProperities(HttpContext context, string requestType, string url, string pathTranslated);
    }
}
